package one.stand.service;

import com.alibaba.fastjson.JSON;
import one.stand.OneUserServiceApplicationTests;
import one.stand.code.RedisCode;
import one.stand.entity.TokenEntity;
import one.stand.request.BusinessCardRequest;
import one.stand.request.TokenRequest;
import one.stand.util.RedisUtil;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Base64;
import java.util.concurrent.TimeUnit;

@TestConfiguration
public class BusinessCard extends OneUserServiceApplicationTests {
    @Autowired
    protected RedisUtil redisUtil;
    @Autowired
    BusinessCardService businessCardService;
    @Autowired
    PosterService posterService;
    public static void main(String[] args) throws IOException {

        String url = "D:/安装包/apiclient_cert.p12";
        File file = new File(url);
        FileInputStream inputFile = new FileInputStream(file);
        byte[] buffer = new byte[(int) file.length()];
        inputFile.read(buffer);
        inputFile.close();
        String data = new String(Base64.getEncoder().encode(buffer));
        System.err.println("base64:" + data + "-" + data.length());
    }

    @Test
    public void addCard() {
        BusinessCardRequest request = new BusinessCardRequest();
        TokenRequest tokenRequest = new TokenRequest();
        tokenRequest.setId(1L);
        request.setName("QIk");
        request.setPhone("15928444521");
        request.setCompanyId(1);
        request.setStyle(1);
        System.err.println(JSON.toJSON(businessCardService.createCard(request)));
    }

    @Test
    public void getCardPoster() {
        System.err.println(JSON.toJSONString(posterService.getCardPoster(new BusinessCardRequest(){{
            setCardId(278);
            setId(117L);
        }})));
    }

    @Test
    public void getLoginInfo() {
        String token = "fksdjfdskjdsf_17";
        System.err.println(JSON.toJSONString(redisUtil.get(RedisCode.getUserLoginToken(token))));
        TokenEntity tokenModel = new TokenEntity();
        tokenModel.setRoleId(1221122223);
        redisUtil.set(RedisCode.getUserLoginToken(token), tokenModel, 7000, TimeUnit.SECONDS);
        System.err.println(JSON.toJSONString(redisUtil.get(RedisCode.getUserLoginToken(token))));
    }

}
